package com.unidue.foguing.task_A;

import java.io.IOException;
import java.util.HashSet;

import com.unidue.foguing.helper.BaseLineBase;
/**
 * this class make the preprocessing of each subTweet and set the polarity based on the number of positive 
 * and negative words contained in the subTweet.
 * @author foguing
 *
 */
public class BaseLine_TaskA extends BaseLineBase {
	
	final String[] pos_emoticons = {":-)", ":)", ":))" , "(-:", "(:", "b-)", ";-)", ";)" , ":d"};
	final String[] neg_emoticons = {":-(", ":(", ")-:", "):"};
	
	@Override
	public String getSentimentPolarity(String processedSubTweet) {
		String polarity = null;
		int positiveWords = 0;
		int negativeWords = 0;
		
		HashSet<String> positiveSetOfWords = null;
		HashSet<String> negativeSetOfWords = null;
		
		try {
			positiveSetOfWords = getSetOfPositiveWords();
		} catch (IOException e) {
			System.out.println(e.getMessage());;
		}
		
		try {
			negativeSetOfWords = getSetOfNegativeWords();
		} catch (IOException e) {
			System.out.println(e.getMessage());;
		}
		
		HashSet<String> positiveEmoticons = getSetOfPositiveEmoticons();
		HashSet<String> negativeEmoticons = getSetOfNegativeEmoticons();
		String[] array = processedSubTweet.split(" ");
		for(String str : array){
			if(positiveSetOfWords.contains(str.trim()) || positiveEmoticons.contains(str.trim()) ){
				positiveWords++;
			}
			if(negativeSetOfWords.contains(str.trim()) || negativeEmoticons.contains(str.trim())){
				negativeWords++;
			}
			int sum = positiveWords - negativeWords;
			if(sum > 0){
				polarity = "positive";
			}else if(sum < 0){
				polarity = "negative";
			}else{
				polarity = "neutral";
			}
			
		}
		return polarity;
	}

	/**
	 * this method put all positive emoticons in a hashset.
	 * @return the set of positive emoticons
	 */
	public HashSet<String> getSetOfPositiveEmoticons(){
		HashSet<String> positiveEmoticons = new HashSet<String>();
		for(String str : pos_emoticons){
			positiveEmoticons.add(str);
		}
		return positiveEmoticons;
	}
	
	/**
	 * this method put all negative emoticons in a hashset.
	 * @return
	 * 		the set of negative emoticons
	 */
	public HashSet<String> getSetOfNegativeEmoticons(){
		HashSet<String> negativeEmoticons = new HashSet<String>();
		for(String str : pos_emoticons){
			negativeEmoticons.add(str);
		}
		return negativeEmoticons;
	}
	
}
